home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.4)
-
- """Test program for MimeWriter module.
-
- The test program was too big to comfortably fit in the MimeWriter
- class, so it's here in its own file.
-
- This should generate Barry's example, modulo some quotes and newlines.
-
- """
- from MimeWriter import MimeWriter
- SELLER = 'INTERFACE Seller-1;\n\nTYPE Seller = OBJECT\n DOCUMENTATION "A simple Seller interface to test ILU"\n METHODS\n price():INTEGER,\n END;\n'
- BUYER = 'class Buyer:\n def __setup__(self, maxprice):\n self._maxprice = maxprice\n\n def __main__(self, kos):\n """Entry point upon arrival at a new KOS."""\n broker = kos.broker()\n # B4 == Barry\'s Big Bass Business :-)\n seller = broker.lookup(\'Seller_1.Seller\', \'B4\')\n if seller:\n price = seller.price()\n print \'Seller wants $\', price, \'... \'\n if price > self._maxprice:\n print \'too much!\'\n else:\n print "I\'ll take it!"\n else:\n print \'no seller found here\'\n'
- STATE = '# instantiate a buyer instance and put it in a magic place for the KOS\n# to find.\n__kp__ = Buyer()\n__kp__.__setup__(500)\n'
- SIMPLE_METADATA = [
- ('Interpreter', 'python'),
- ('Interpreter-Version', '1.3'),
- ('Owner-Name', 'Barry Warsaw'),
- ('Owner-Rendezvous', 'bwarsaw@cnri.reston.va.us'),
- ('Home-KSS', 'kss.cnri.reston.va.us'),
- ('Identifier', 'hdl://cnri.kss/my_first_knowbot'),
- ('Launch-Date', 'Mon Feb 12 16:39:03 EST 1996')]
- COMPLEX_METADATA = [
- ('Metadata-Type', 'complex'),
- ('Metadata-Key', 'connection'),
- ('Access', 'read-only'),
- ('Connection-Description', "Barry's Big Bass Business"),
- ('Connection-Id', 'B4'),
- ('Connection-Direction', 'client')]
- EXTERNAL_METADATA = [
- ('Metadata-Type', 'complex'),
- ('Metadata-Key', 'generic-interface'),
- ('Access', 'read-only'),
- ('Connection-Description', 'Generic Interface for All Knowbots'),
- ('Connection-Id', 'generic-kp'),
- ('Connection-Direction', 'client')]
-
- def main():
- import sys
- toplevel = MimeWriter(sys.stdout)
- toplevel.addheader('From', 'bwarsaw@cnri.reston.va.us')
- toplevel.addheader('Date', 'Mon Feb 12 17:21:48 EST 1996')
- toplevel.addheader('To', 'kss-submit@cnri.reston.va.us')
- toplevel.addheader('MIME-Version', '1.0')
- f = toplevel.startmultipartbody('knowbot', '801spam999', [
- ('version', '0.1')], prefix = 0)
- f.write('This is a multi-part message in MIME format.\n')
- md = toplevel.nextpart()
- md.startmultipartbody('knowbot-metadata', '802spam999')
- md1 = md.nextpart()
- md1.addheader('KP-Metadata-Type', 'simple')
- md1.addheader('KP-Access', 'read-only')
- m = MimeWriter(md1.startbody('message/rfc822'))
- for key, value in SIMPLE_METADATA:
- m.addheader('KPMD-' + key, value)
-
- m.flushheaders()
- del md1
- md2 = md.nextpart()
- for key, value in COMPLEX_METADATA:
- md2.addheader('KP-' + key, value)
-
- f = md2.startbody('text/isl')
- f.write(SELLER)
- del md2
- md3 = md.nextpart()
- f = md3.startbody('message/external-body', [
- ('access-type', 'URL'),
- ('URL', 'hdl://cnri.kss/generic-knowbot')])
- m = MimeWriter(f)
- for key, value in EXTERNAL_METADATA:
- md3.addheader('KP-' + key, value)
-
- md3.startbody('text/isl')
- md.lastpart()
- code = toplevel.nextpart()
- code.startmultipartbody('knowbot-code', '803spam999')
- buyer = code.nextpart()
- buyer.addheader('KP-Module-Name', 'BuyerKP')
- f = buyer.startbody('text/plain')
- f.write(BUYER)
- code.lastpart()
- state = toplevel.nextpart()
- state.addheader('KP-Main-Module', 'main')
- state.startmultipartbody('knowbot-state', '804spam999')
- st = state.nextpart()
- st.addheader('KP-Module-Name', 'main')
- f = st.startbody('text/plain')
- f.write(STATE)
- state.lastpart()
- toplevel.lastpart()
-
- main()
-